﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sms_Template_View.aspx.cs" Inherits="JKF.Web.SMS.Templeate.Sms_Template_View" %>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <%= RegScript("~/js/jquery.1.5.js")%>
    <%= RegScript("~/js/jquery.nhis.js")%>
    <%= RegScript("~/js/jquery.rchis.js")%>
    <%= RegScript("~/js/jquery-ui-custom.min.js")%>
    <%=RegScript("~/js/jquery.json.js")%>
    <%= RegScript("~/js/css.js")%>
    <%= RegScript("~/js/DatePicker/WdatePicker.js")%>
    <%= RegScript("~/js/Common.js")%>
    <%= RegScript("~/js/Jquery.commonGrid.js")%>
    <%= RegStyle("~/App_Themes/Theme2/Include.css")%>
    <script type="text/javascript">
        var AppPath = '<%=AppPath %>';
        var handler = AppPath + '/do/SMS/SmsModule.do';
        var tmpl = new DTemplate();
        var PageSize = 20;
        var pager = null;
        var advSearch = null;
        var rowTemplate = "<tr pk=\"${ID}\"><td><input type=\"button\" class=\"op-edit common_btn_edit mr12\" style=\"display:<%=DispEdit%>\"/><input type=\"button\" class=\"op-del common_btn_del mr12\" style=\"display:<%=DispAdd%>\"/></td><td>${TEMPLEATE_NAME}</td><td>${CONTENT}</td><td>${IS_START}</td><td>${OPERATOR}</td><td>${DATE_CREATE}</td></tr>";
        $(function () {
            pager = $('#divPager').pager(AppPath, handler, function () {
                return {
                    ActionName: 'GetSmsTemplateByPage',
                    schOptions: $.toJSON({
                        IS_START: $("#TemplateState").val(),
                        TEMPLEATE_NAME: $("#TemplateName").val()
                    })
                };
            }, function (data) {
                var tbody = $('#tb tbody');
                tbody.empty();
                if (data && data.Entity && data.Entity.length) {
                    tbody.html(tmpl(rowTemplate, data.Entity, true));
                } else {
                    tbody.html('<tr><td colspan="6" style="text-align: center">没有数据!</td></tr>');
                }
                BindGridEvent();
                $("#tb").H8_Grid($("#divPager"), (function (){var tbHeight = $(window).height()-35; tbHeight-=($(".common_search").size()>0)?$(".common_search").eq(0).height():0; tbHeight-=($("#divPager").size()>0)?$("#divPager").height():0; return tbHeight < 300 ? 300 : tbHeight;})());
            }, PageSize, true);

            $('#btnSearch').click(function () {
                advSearch = null;
                pager.option.pageIndex = 1;
                pager.getPegerData();
                return false;
            });

            $("#btnAdd").click(Add);
        });
        //弹出层
        function Add(id) { window.parent.pop($.FxNull(id, "") == "" ? "添加短信模版" : "编辑短信模版", '<%= ResolveUrl("~/SMS/Templeate/Sms_Template_Add.aspx?id=") %>' + $.FxNull(id, ""), 860, 400, updateList); };

        function updateList(obj) {
            var tbody = $('#tb tbody');
            var key = $.FxNull(obj.ID, "");
            if (tbody.find("tr[pk]").size() == 0) tbody.empty();
            if (key == "") return;
            var editRow = tbody.find("tr[pk='" + key + "']");
            var newRow = $(tmpl(rowTemplate, obj, true));
            if (editRow.size() == 0) {
                tbody.prepend(newRow);
                addCount(); //添加成功之后更新记录总条数
            } else {
                newRow.insertAfter(editRow);
                editRow.remove();
            }
            $("#tb").H8_Grid($("#divPager"), (function (){var tbHeight = $(window).height()-35; tbHeight-=($(".common_search").size()>0)?$(".common_search").eq(0).height():0; tbHeight-=($("#divPager").size()>0)?$("#divPager").height():0; return tbHeight < 300 ? 300 : tbHeight;})());
            BindGridEvent();
        }

        function BindGridEvent() {
            var tbl = $("#tb>tbody");
            tbl.find(".op-edit").click(function () { Add($(this).parent().parent().attr("pk")); });
            tbl.find(".op-del").click(function () {
                if (!confirm("确认要删除此项吗？")) return;
                var tr = $(this).parent().parent();
                $.post(handler, { ActionName: "RemoveSmsTemplate", id: $(this).parent().parent().attr("pk") }, function (rslt) {
                    if (rslt.Success) {
                        tr.remove();
                        reduceCount();//减少记录总条数
                        return;
                    }
                    alert(rslt.Data);
                }, "json");
            });
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="warrper_body">
            <div class="index">
                <div class="common_search">
                    <div class="l_h45">
                        <span class="mr30 mb20">模版名称：
                        <input type="text" id="TemplateName" class="common_search_input w150" />
                        </span>
                        <span class="mr30 mb20">状态：
                        <select id="TemplateState" class="common_search_select w150">
                            <option value="">请选择</option>
                            <option value="1">启用</option>
                            <option value="0">停用</option>
                        </select>
                        </span>
                        <input type="button" class="common_btn_search" id="btnSearch" />
                        <input type="button" id="btnAdd" value="" class="common_btn_add2" style="display: <%=DispAdd%>" />
                    </div>
                </div>
                <div class="l_h7"></div>
                <div class="index_table">
                    <table id="tb" class="common_table">
                        <thead>
                            <tr>
                                <th width="100px" orderaction="false">操作
                                </th>
                                <th width="100px" ordertype="string">模版名称
                                </th>
                                <th width="300px" ordertype="string">内容
                                </th>
                                <th width="100px" ordertype="string">是否启用
                                </th>
                                <th width="100px" ordertype="string">创建人
                                </th>
                                <th width="100px" ordertype="string">创建时间
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td colspan="6" style="text-align: center">点击搜索查看数据
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>
                <div class="H8_Grid_page" id="divPager">
                </div>
            </div>
        </div>
    </form>
</body>
</html>
